/*
 * MIT License
 *
 * Copyright (c) 2023 北京凯特伟业科技有限公司
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.je.message.service.log.impl;

import com.je.common.base.service.CommonService;
import com.je.common.base.service.MetaService;
import com.je.common.base.service.rpc.SystemSettingRpcService;
import com.je.common.base.util.SecurityUserHolder;
import com.je.message.Push;
import com.je.message.service.log.AbstractLogService;
import com.je.message.vo.LogMsg;
import com.je.message.vo.MessageVo;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @ClassName
 * @Author wangchao
 * @Date 2022/4/27 0027 10:11
 * @Version V1.0
 */
public abstract class AbstractLogServiceImpl implements AbstractLogService {
    @Autowired
    protected MetaService metaService;
    @Autowired
    protected SystemSettingRpcService systemSettingRpcService;
    @Autowired
    protected CommonService commonService;

    @Override
    public void saveCodeLog(LogMsg message){};

    @Override
    public  void saveAllLog(MessageVo msgVo, Push type){
        LogMsg logMsg = new LogMsg();
        logMsg.setFromUser(SecurityUserHolder.getCurrentAccountRealUserName());
        logMsg.setFromUserId(SecurityUserHolder.getCurrentAccountRealUserId());
        logMsg.setContext(msgVo.getMsgContent());
        logMsg.setSubject(msgVo.getMsgOwner());
        logMsg.setToUserId(msgVo.getUserIds());
        logMsg.setDeptIds(msgVo.getDeptIds());
        logMsg.setResult(msgVo.getResult());
        logMsg.setErrorMessage(msgVo.getErrorMessage());
        logMsg.setFileKey(msgVo.getFileKey());
        logMsg.setUrl(msgVo.getUrl());
        logMsg.setTitle(msgVo.getTitle());
        logMsg.setButtonText(msgVo.getButtonText());

        if (type.getCode().equals(Push.WELINK.getCode())) {
            logMsg.setFl(Push.WELINK.getCode());
            logMsg.setTitle(msgVo.getMsgTitle());
            logMsg.setDeptIds(msgVo.getDepartmentList());
            logMsg.setUrl(msgVo.getUrlPath());
        }else if(type.getCode().equals(Push.LARK.getCode())){
            logMsg.setFl(Push.LARK.getCode());

        }else if(type.getCode().equals(Push.WECHAT.getCode())){
            logMsg.setFl(Push.WECHAT.getCode());
            logMsg.setSourceUrl(msgVo.getSourceUrl());

        }else if(type.getCode().equals(Push.DINGTALK.getCode())){
            logMsg.setFl(Push.DINGTALK.getCode());
        }
        saveLog(logMsg);
    }
}
